package com.xgh.design.adapter;

import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName Test
 * @Description
 * @Author xinggh
 * @Date 2020/8/6 19:36
 * @Version 1.0
 **/
public class Test {

    private List<DC5Adapter> adapters = new LinkedList<DC5Adapter>();

    public Test() {
        this.adapters.add(new CHNAdapter());
        this.adapters.add(new JPAAdapter());
    }

    public static void main(String[] args) {
        Test test = new Test();
        AC ac220 = new AC220();
        DC5Adapter adapter = test.getAdapter(ac220);
        adapter.outputDC5V(ac220);
    }

    public DC5Adapter getAdapter(AC ac) {
        for (DC5Adapter d : adapters) {
            if (d.support(ac)) {
                return d;
            }
        }
        System.out.println("未找到合适的适配器。。");
        return null;
    }
}
